package servlet;

import bean.GoodsBean;
import bean.WarehouseBean;
import util.JdbcUtil;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class InventoryModifyServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
           doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int iid =Integer.parseInt(request.getParameter("iid"));
        String sql ="SELECT * FROM inventory Where iid=?";
        try {
            PreparedStatement ps = JdbcUtil.getConnection().prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
            ps.setInt(1,iid);
            ResultSet set = ps.executeQuery();
            set.absolute(1);
            GoodsBean gb = new GoodsBean();
            gb.setIid(set.getInt(1));
            gb.setType(set.getString(2));
            gb.setWid(set.getInt(3));
            gb.setWname(set.getString(4));
            gb.setNumber(set.getInt(5));
            gb.setStaff(set.getString(6));
            HttpSession session = request.getSession();
            session.setAttribute("gb",gb);
            request.getRequestDispatcher("inventorymodify.jsp").forward(request,response);
        }catch (Exception e) {
            e.printStackTrace();
        }


    }
}

